import utils from '../../utils';

const LINE_LOADING = 'app/LINE_LOADING';
const LINE_LOADING_OVER = 'app/LINE_LOADING_OVER';
const GET_USER_INFO = 'app/GET_USER_INFO';

const initialState = {
    data: {},
    loadover: false,
    lineloading: false
};

export default function reducer(state = initialState, action = {}) {
    switch (action.type) {
        case LINE_LOADING:
            return {
                ...state,
                lineloading: true
            };
        case LINE_LOADING_OVER:
            return {
                ...state,
                lineloading: false
            };
        case GET_USER_INFO:
            return {
                ...state,
                data: action.data,
                loadover: true
            };
        default:
            return state;
    }
}

export function startLineLoading() {
    return {
        type: LINE_LOADING
    };
}

export function killLineLoading() {
    return {
        type: LINE_LOADING_OVER
    };
}

export const getUserInfo = utils.createAction(
    GET_USER_INFO,
    ({ctxCookie = ''} = {}) => utils.get('/api/user', null, ctxCookie)
);
